home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / portfoli / bootst11.lzh / PF BOOTSTRAP VATIPX PLIBACUBIZC < prev    next >
Text File  |  1989-05-13  |  3KB  |  171 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)biz22.c    5.2 (Berkeley) 9/13/88";
  20. #endif /* not lint */
  21.  
  22. #include "tip.h"
  23.  
  24. #define DISCONNECT_CMD    "\20\04"    /* disconnection string */
  25.  
  26. static    int sigALRM();
  27. static    int timeout = 0;
  28. static    jmp_buf timeoutbuf;
  29.  
  30. /*
  31.  * Dial up on a BIZCOMP Model 1022 with either
  32.  *     tone dialing (mod = "V")
  33.  *    pulse dialing (mod = "W")
  34.  */
  35. static int
  36. biz_dialer(num, mod)
  37.     char *num, *mod;
  38. {
  39.     register int connected = 0;
  40.     char cbuf[40];
  41.  
  42.     if (boolean(value(VERBOSE)))
  43.         printf("\nstarting call...");
  44.     /*
  45.      * Disable auto-answer and configure for tone/pulse
  46.      *  dialing
  47.      */
  48.     if (cmd("\02K\r")) {
  49.         printf("can't initialize bizcomp...");
  50.         return (0);
  51.     }
  52.     strcpy(cbuf, "\02.\r");
  53.     cbuf[1] = *mod;
  54.     if (cmd(cbuf)) {
  55.         printf("can't set dialing mode...");
  56.         return (0);
  57.     }
  58.     strcpy(cbuf, "\02D");
  59.     strcat(cbuf, num);
  60.     strcat(cbuf, "\r");
  61.     write(FD, cbuf, strlen(cbuf));
  62.     if (!detect("7\r")) {
  63.         printf("can't get dial tone...");
  64.         return (0);
  65.     }
  66.     if (boolean(value(VERBOSE)))
  67.         printf("ringing...");
  68.     /*
  69.      * The reply from the BIZCOMP should be:
  70.      *    2 \r or 7 \r    failure
  71.      *    1 \r        success
  72.      */
  73.     connected = detect("1\r");
  74. #ifdef ACULOG
  75.     if (timeout) {
  76.         char line[80];
  77.  
  78.         sprintf(line, "%d second dial timeout",
  79.             number(value(DIALTIMEOUT)));
  80.         logent(value(HOST), num, "biz1022", line);
  81.     }
  82. #endif
  83.     if (timeout)
  84.         biz22_disconnect();    /* insurance */
  85.     return (connected);
  86. }
  87.  
  88. biz22w_dialer(num, acu)
  89.     char *num, *acu;
  90. {
  91.  
  92.     return (biz_dialer(num, "W"));
  93. }
  94.  
  95. biz22f_dialer(num, acu)
  96.     char *num, *acu;
  97. {
  98.  
  99.     return (biz_dialer(num, "V"));
  100. }
  101.  
  102. biz22_disconnect()
  103. {
  104.     int rw = 2;
  105.  
  106.     write(FD, DISCONNECT_CMD, 4);
  107.     sleep(2);
  108.     ioctl(FD, TIOCFLUSH, &rw);
  109. }
  110.  
  111. biz22_abort()
  112. {
  113.  
  114.     write(FD, "\02", 1);
  115. }
  116.  
  117. static int
  118. sigALRM()
  119. {
  120.  
  121.     timeout = 1;
  122.     longjmp(timeoutbuf, 1);
  123. }
  124.  
  125. static int
  126. cmd(s)
  127.     register char *s;
  128. {
  129.     char c;
  130.     sigfunc_t (*f)();
  131.  
  132.     write(FD, s, strlen(s));
  133.     f = signal(SIGALRM, sigALRM);
  134.     if (setjmp(timeoutbuf)) {
  135.         biz22_abort();
  136.         signal(SIGALRM, f);
  137.         return (1);
  138.     }
  139.     alarm(number(value(DIALTIMEOUT)));
  140.     read(FD, &c, 1);
  141.     alarm(0);
  142.     signal(SIGALRM, f);
  143.     c &= 0177;
  144.     return (c != '\r');
  145. }
  146.  
  147. static int
  148. detect(s)
  149.     register char *s;
  150. {
  151.     char c;
  152.     sigfunc_t (*f)();
  153.  
  154.     f = signal(SIGALRM, sigALRM);
  155.     timeout = 0;
  156.     while (*s) {
  157.         if (setjmp(timeoutbuf)) {
  158.             biz22_abort();
  159.             break;
  160.         }
  161.         alarm(number(value(DIALTIMEOUT)));
  162.         read(FD, &c, 1);
  163.         alarm(0);
  164.         c &= 0177;
  165.         if (c != *s++)
  166.             return (0);
  167.     }
  168.     signal(SIGALRM, f);
  169.     return (timeout == 0);
  170. }
  171.